package com.charlotte.study.gupao.composite.transparent;

import java.util.ArrayList;
import java.util.List;

/**
 * @author junjie.ding
 * @date 2020/3/10
 */
public class CoursePackage extends CourseComponent {

    private List<CourseComponent> children = new ArrayList<>();

    private String name;

    private Integer level;

    public CoursePackage(String name, Integer level) {
        this.name = name;
        this.level = level;
    }

    @Override
    public void addChild(CourseComponent catalogComponent) {
        this.children.add(catalogComponent);
    }

    @Override
    public void removeChild(CourseComponent catalogComponent) {
        this.children.remove(catalogComponent);
    }

    @Override
    public String getName(CourseComponent catalogComponent) {
        return this.name;
    }

    @Override
    public void print() {
        System.out.println(this.name);
        for(CourseComponent catalogComponent : children){
            //控制显示格式
            if(this.level != null){
                for(int i = 0; i < this.level; i ++){
                //打印空格控制格式
                    System.out.print("   ");
                }for(int i = 0; i < this.level; i ++){
                //每一行开始打印一个+号
                    if(i == 0){ System.out.print("+"); }
                    System.out.print("-");
                }
            }
            //打印标题
            catalogComponent.print();
        }
    }
}
